

<template>
  <div class="rightCZ">
    <!-- <div class="buts">
      <el-button type="success" @click="save()">保存</el-button>
    </div> -->
    <div class="userinfo">
      <div>
        姓名：<span>{{ thatF.PatientInfoDatathird.member_info.name }}</span>
      </div>
      <div>
        挂号初复诊：<span>{{
            thatF.PatientInfoDatathird.look_type == 1 ? "初诊" : "复诊"
        }}</span>
      </div>
      <div>
        门诊号：<span>{{ thatF.PatientInfoDatathird.patient_no }}</span>
      </div>
    </div>
    <div style="margin-bottom: 10px">
      <el-button @click="addChuagfag">开立处方</el-button>
      <el-button @click="addChuagfag2">开立诊疗</el-button>
      <el-button @click="addzhenduan('zd_use_medical_record_tpl_id')">诊断证明</el-button>
      <el-dropdown @command="addzhenduan">
        <el-button type="primary">
          检查单<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="jcjy_medical_record_tpl_id">检查检验申请单</el-dropdown-item>
          <el-dropdown-item command="bc_medical_record_tpl_id">B超申请单</el-dropdown-item>
          <el-dropdown-item command="jc_medical_record_tpl_id">检查申请单</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="药品处方" name="one">
        <el-table v-loading="chufangLoading" highlight-current-row :data="thatF.chufangData1"
          @row-click="handleCurrentChange" style="width: 100%">
          <el-table-column type="index" label="序号" width="50">
          </el-table-column>
          <template v-for="(item, index) in tableTitle1">
            <el-table-column :width="item.width" v-if="item.prop == 'medical_record.diagnosis'" :prop="item.prop"
              :label="item.label" :key="index">
              <template slot-scope="scope">
                <span v-if="scope.row.medical_record.diagnosis">
                  <span v-for="(item, diag_index) in scope.row.medical_record
                  .diagnosis" :key="diag_index">
                    {{ item.name }}
                  </span>
                </span>
              </template>
            </el-table-column>
            <el-table-column :width="item.width" v-else-if="item.prop == 'order_type'" :prop="item.prop"
              :label="item.label" :key="index">
              <template slot-scope="scope">
                <span>
                  <span v-if="scope.row.order_type == 1"> 普通处方 </span>
                  <span v-if="scope.row.order_type == 2"> 诊疗处方 </span>
                  <span v-if="scope.row.order_type == 3"> 二类处方 </span>
                  <span v-if="scope.row.order_type == 4"> 中成药处方 </span>
                  <span v-if="scope.row.order_type == 5"> 中药饮片处方 </span>
                </span>
              </template>
            </el-table-column>

            <el-table-column :width="item.width" v-else :prop="item.prop" :label="item.label" :key="index">
            </el-table-column>
          </template>
          <el-table-column label="操作" width="250" fixed="right">
            <template slot-scope="scope">
              <div>
                <el-button size="mini" class="butB_Add" @click="handleEdit(scope.$index, scope.row, 1)">修改</el-button>
                <el-button size="mini" class="butB_Add" @click.native.prevent="handleEdit(scope.$index, scope.row, 3)">
                  打印</el-button>
                <el-button size="mini" class="butB_Del" @click="handleEdit(scope.$index, scope.row, 2)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>

        <div style="margin: 20px 0" v-if="thatF.order_tyte != 2">
          <ViewTitle text="处方信息" />
        </div>
        <div style="padding: 20px 0px" v-if="thatF.order_tyte != 2">
          处方备注：{{ cf_remark }}
        </div>
        <el-table v-if="thatF.order_tyte != 2" :data="thatF.chufangData2.drug" v-loading="thatF.YZ_chufang_info_loading"
          style="width: 100%">
          <template v-for="(item, index) in tableTitle2">
            <el-table-column :width="item.width" v-if="item.prop == 'each_dos'" :prop="item.prop" :label="item.label"
              :key="index">
              <template slot-scope="scope">
                <span v-if="scope.row.each_dos">
                  <span v-if="!isNaN(scope.row.each_dos)">{{
                      thatF.pinci.find((res) => res.id == scope.row.each_dos)[
                      "name"
                      ]
                  }}</span>
                </span>
              </template>
            </el-table-column>
            <el-table-column :width="item.width" v-else-if="item.prop == 'usage'" :prop="item.prop" :label="item.label"
              :key="index">
              <template slot-scope="scope">
                <span v-if="scope.row.usage && isNaN(scope.row.usage) === false">
                  <span class="on" v-if="!isNaN(scope.row.usage)">{{
                      thatF.geiyao.find((res) => res.id == scope.row.usage)[
                      "name"
                      ]
                  }}</span>
                </span>
                <span v-else> {{ scope.row.usage }}</span>
              </template>
            </el-table-column>

            <el-table-column v-else-if="item.prop == 'num'" :width="item.width" :prop="item.prop" :label="item.label"
              :key="index">
              <template slot-scope="scope">
                <span>
                  {{ scope.row.num }}
                </span>
              </template>
            </el-table-column>

            <el-table-column :width="item.width" v-else-if="item.prop == 'is_skin_test'" :prop="item.prop"
              :label="item.label" :key="index">
              <template slot-scope="scope">
                <span>
                  <el-checkbox disabled v-model="scope.row.is_skin_test"></el-checkbox>
                </span>
              </template>
            </el-table-column>
            <el-table-column :width="item.width" v-else-if="item.prop == 'trans_speed'" :prop="item.prop"
              :label="item.label" :key="index">
              <template slot-scope="scope">
                <span>
                  <span v-if="scope.row.trans_speed">
                    <span v-if="!isNaN(scope.row.trans_speed)">{{
                        thatF.disu.find((res) => res.id == scope.row.trans_speed)[
                        "name"
                        ]
                    }}</span>
                  </span>
                </span>
              </template>
            </el-table-column>

            <el-table-column :width="item.width" v-else-if="item.prop == 'usage_extra'" :prop="item.prop"
              :label="item.label" :key="index">
              <template slot-scope="scope">
                <span v-if="scope.row.usage">
                  <span class="on" v-if="!isNaN(scope.row.usage_extra)">{{
                      thatF.xiyaojiaozhu.find(
                        (res) => res.id == scope.row.usage_extra
                      )["name"]
                  }}</span>
                </span>
              </template>
            </el-table-column>
            <el-table-column :width="item.width" v-else-if="item.prop == 'remark'" :prop="item.prop" :label="item.label"
              :key="index">
              <template slot-scope="scope">
                <span>
                  <span>
                    {{ scope.row.remark }}
                  </span>
                </span>
              </template>
            </el-table-column>

            <el-table-column :width="item.width" v-else :prop="item.prop" :label="item.label" :key="index">
            </el-table-column>
          </template>
        </el-table>

        <div style="margin: 20px 0" v-if="thatF.order_tyte == 2">
          <ViewTitle text="诊疗信息" />
        </div>
        <el-table v-if="thatF.order_tyte == 2" :data="thatF.chufangData2.service"
          v-loading="thatF.YZ_chufang_info_loading" style="width: 100%">
          <template v-for="(item, index) in tableTitle3">
            <el-table-column :width="item.width" v-if="item.prop == 'is_fast'" :prop="item.prop" :label="item.label"
              :key="index">
              <template slot-scope="scope">
                <span>
                  <el-checkbox disabled v-model="scope.row.is_fast"></el-checkbox>
                </span>
              </template>
            </el-table-column>

            <el-table-column :width="item.width" v-else :prop="item.prop" :label="item.label" :key="index">
            </el-table-column>
          </template>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="患者病历" name="two">
        <bllist :thatF="this" ref="bllist"></bllist>
        <!-- <el-button @click="bl.show=true">病历列表</el-button> -->
      </el-tab-pane>
      <el-tab-pane label="医技报告" name="three">模块开发中.....</el-tab-pane>
    </el-tabs>

    <!-- <div class="bl">
      <el-dialog
        :visible.sync="bl.show"
        v-if="bl.show"
         :close-on-press-escape="false"
        :close-on-click-modal="false"
        title="列表"
        :modal-append-to-body="false"
        :destroy-on-close="true"
      >

        <bllist :thatF="this" ref="bllist"></bllist>
      </el-dialog>
    </div> -->
    <el-dialog :visible.sync="modal.selectPrintShow" v-if="modal.selectPrintShow" :close-on-press-escape="false"
      :close-on-click-modal="false" title="打印" :modal-append-to-body="false" :destroy-on-close="true">

      <selectPrint :data="chufangdata" :order_type="order_type"></selectPrint>
    </el-dialog>
    <el-dialog title="打印" :fullscreen="true" :modal-append-to-body="false" :visible.sync="chufang">
      <chufangje v-if="order_type == 3" :cfdata="chufangdata"></chufangje>
      <chufang v-else :cfdata="chufangdata"></chufang>
    </el-dialog>
  </div>
</template>
<script>
import ViewTitle from "@/forComponents/viewTitle/index.vue";
import bllist from "./bl/list.vue";
import chufang from "./bl/chufang.vue";
import chufangje from "./bl/chufangje.vue";
import selectPrint from "./selectPrint.vue"
import { iframeUrl, http2 } from "@/utils/server.js";
import { Loading } from "element-ui";
import { mapState, mapMutations, mapActions } from "vuex";
export default {
  props: ["thatF"],

  data() {
    return {
      modal: {
        selectPrintShow: false,
      },
      cf_remark: "",
      bl: {
        show: false,
        member_id: "",
      },
      activeName: "one",
      tableData1: [],
      tableData2: [],
      chufangLoading: false,
      tableTitle1: [
        {
          prop: "order_type",
          label: "处方类型",
        },
        {
          prop: "number",
          label: "处方单号",
        },
        {
          prop: "member.name",
          label: "姓名",
        },
        {
          prop: "patient_no",
          label: "门诊号",
        },
        {
          prop: "updated_at",
          label: "就诊时间",
        },
        {
          prop: "doctor.dept_name",
          label: "科室",
        },
        {
          prop: "doctor.real_name",
          label: "医生",
        },
        {
          prop: "medical_record.diagnosis",
          label: "诊断",
          width: "150",
        },

        {
          prop: "should_amount",
          label: "金额",
        },
        // {
        //   prop: "pay_status",
        //   label: "初复诊",
        // },
        // {
        //   prop: "amount",
        //   label: "处方金额",
        // },
      ],
      order_type: "",
      tableTitle2: [
        {
          prop: "drug.name",
          label: "药品名称",
          width: "150",
        },
        {
          prop: "yb_code",
          label: "医保编码",
          width: "200",
        },
        {
          prop: "drug.specification",
          label: "规格",
          width: "150",
        },
        {
          prop: "dose",
          label: "单次剂量",
          width: "100",
        },
        {
          prop: "dose_unit",
          label: "剂量单位",
          width: "100",
        },
        {
          prop: "each_dos",
          label: "频次",
          width: "150",
        },
        {
          prop: "usage",
          label: "用法",
          width: "150",
        },
        {
          prop: "num",
          label: "数量",
        },
        {
          prop: "drug.base_unit",
          label: "单位",
        },
        {
          prop: "is_skin_test",
          label: "皮试",
        },

        //{
        //   prop:"usage_extra",
        //   label:"西药脚注",
        //   width:'150'
        // },
        {
          prop: "drug.fee_category.name",
          label: "费用种类",
        },
      ],
      tableTitle3: [
        {
          prop: "service.name",
          label: "项目名称",
          width: "200",
        },
        // {
        //   prop: "position",
        //   label: "检测部位",
        // },
        {
          prop: "once",
          label: "次数",
        },
        {
          prop: "price",
          label: "单价",
        },
        {
          prop: "is_fast",
          label: "是否加急",
        },
        {
          prop: "remark",
          label: "开立备注",
          width: "150",
        },
        {
          prop: "service.execute_dept.name",
          label: "执行科室",
        },
        {
          prop: "service.yb_code",
          label: "医保编号",
          width: "200",
        },

        {
          prop: "service.yb_proportion",
          label: "医保比例",
        },
        {
          prop: "service.yb_type",
          label: "医保类型",
        },
      ],
      chufang: false,
      chufangdata: {},
    };
  },
  mounted() {
    this.tableTitle = [];
  },
  computed: {
    ...mapState({
      YZ_chufang_status: (state) => state.doctorWorkStation.YZ_chufang_status,
      service_print_list: (state) => state.doctorWorkStation.service_print_list,
    }),
  },
  methods: {
    ...mapMutations(["doctorWorkStation/set_YZ_chufang_status"]),
    ...mapActions(["doctorWorkStation/getPrintRecipeItem"]),
    handleClick(item) {
      if (this.activeName == "one") {
      } else if (this.activeName == "two") {
        this.$refs.bllist.getList();
      } else if (this.activeName == "tthreewo") {
      }
    },
    addzhenduan(key2) {
      console.log(key2);
      let loading; //定义loading变量
      loading = Loading.service({
        lock: true,
        text: "加载中……",
        background: "rgba(255,255,255, 0)",
      });
      let d = {
        patient_no: this.thatF.PatientInfoDatathird.patient_no,
      };
      // var http=`${http2}?tepid=72&is_pattern=2&uid=${data.id}&source=4&his_uid=${data.member_info.id}&real_name=${this.real_name}&tep_name="门诊病历"`

      // window.open(http,'_blank');
      this["_API"].getClinic_doctorGetMedicalRecordDetail(d).then((res) => {
        //  this.dialogVisible = true
        //  loading.close()
        let data = res.data;
        this["_API"]
          .getByKey({ key: key2 })
          .then((res2) => {
            var clinic_use_medical_record_tpl_id = "";
            if (res2.code == 200) {
              if (key2 == "zd_use_medical_record_tpl_id") {
                clinic_use_medical_record_tpl_id =
                  res2.data.zd_use_medical_record_tpl_id;
              } else if (key2 == "jcjy_medical_record_tpl_id") {
                clinic_use_medical_record_tpl_id =
                  res2.data.jcjy_medical_record_tpl_id;
              } else if (key2 == "bc_medical_record_tpl_id") {
                clinic_use_medical_record_tpl_id =
                  res2.data.bc_medical_record_tpl_id;
              } else if (key2 == "jc_medical_record_tpl_id") {
                clinic_use_medical_record_tpl_id =
                  res2.data.jc_medical_record_tpl_id;
              }
              // var clinic_use_medical_record_tpl_id= res2.data.key2
              var http = `${http2}?tepid=${clinic_use_medical_record_tpl_id}&is_pattern=2&source=4&his_uid=${data.member_info.id}&real_name=${this.real_name}&tep_name=诊断证明&patient_no=${data.patient_no}`;

              window.open(http, "_blank");

              loading.close();
            }
          })
          .catch((e) => {
            console.log(e);
          });
      });
    },
    handleCurrentChange(elem) {
      this.thatF.order_tyte = elem.order_type;
      this.thatF.updateChuFangData = elem;
      this.cf_remark = elem.remark;
      this.thatF.getClinic_doctorGetRecipeItem(elem.id);
    },
    addChuagfag() {
      this.thatF.order_tyte = 1;

      this["doctorWorkStation/set_YZ_chufang_status"]("add");
      this.thatF.updateChufangDialog = true;
      // this.thatF.getClinic_doctorGetRecipeItem(this.thatF.PatientInfoDatathird.id)
    },
    addChuagfag2() {
      this.thatF.order_tyte = 2;

      this["doctorWorkStation/set_YZ_chufang_status"]("add");
      this.thatF.updateChufangDialog = true;
      // this.thatF.getClinic_doctorGetRecipeItem(this.thatF.PatientInfoDatathird.id)
    },
    // thatF.order_tyte==2
    handleEdit(...item) {
      console.log("item", item);
      // this.chufangLoading = true;

      this.chufangLoading = false;
      this.thatF.order_tyte = item[1].order_type;
      if (item[2] == 1) {
        this["doctorWorkStation/set_YZ_chufang_status"]("update");
        this.thatF.updateChuFangData = item[1];
        this.thatF.updateChufangDialog = true;
        this.thatF.getClinic_doctorGetRecipeItem(item[1].id, "update");
      } else if (item[2] == 2) {
        this["_API"]
          .getClinic_doctorDelRecipe({ id: item[1].id })
          .then((res) => {
            if (res.code == 200) {
              this.thatF.getClinic_doctorGetRecipe(item[1].patient_no);
            }
          });
      } else if (item[2] == 3) {
        setTimeout(() => {

          this.chufangdata = {};
          this.order_type = item[1].order_type;
          // console.log("item[1].order_type",item[1].order_type)
          // return
          console.log("this.thatF.chufangData2", this.thatF.chufangData2)

          if (this.order_type == 2) {

            this['doctorWorkStation/getPrintRecipeItem']({ id: item[1].id }).then(res => {
              Object.assign(this.chufangdata, item[1], { service: this.service_print_list });
              console.log("this.chufangdata>>>>>>>>>>", this.chufangdata)

              this.modal.selectPrintShow = true;
              // console.log("chufangdata",this.chufangdata)
              // console.log("service_print_list",this.service_print_list)
            })
            // this.modal.selectPrintShow=true;
          } else {
            console.log("this.chufangdata", this.chufangdata)
            console.log("this.thatF.chufangData2", this.thatF.chufangData2)
            Object.assign(this.chufangdata, item[1], this.thatF.chufangData2);

            this.chufangdata.drug.forEach((item) => {
              item.drug.each_dos = item.each_dos > 0
                ? this.thatF.pinci.find((res) => res.id == item.each_dos)[
                "name"
                ]
                : "";
              item.drug.usage = item.usage > 0
                ? this.thatF.geiyao.find((res) => res.id == item.usage)["name"]
                : "";
            });
            console.log("this.chufangdata123",this.chufangdata)
            var cfdata = JSON.stringify(this.chufangdata);
            if (this.order_type == 3) {
              const { href } = this.$router.resolve({
                path: "/bai/chufangje",
                query: { cfdata: cfdata },
              });
              window.open(href, "_blank");
            } else {
              const { href } = this.$router.resolve({
                path: "/bai/chufang",
                query: { cfdata: cfdata },
              });
              window.open(href, "_blank");
            }
          }

          // if (
          //   this.order_type != 3 &&
          //   this.order_type != 1 &&
          //   this.order_type != 4
          // ) {
          //   console.log(this.chufangdata.service[0].service, "8888");
          //   this.chufangdata.service.forEach((res) => {
          //     console.log(res);
          //     this.chufangdata.drug.push({
          //       drug: {
          //         name: this.chufangdata.service[0].service.name,
          //         specification: "",
          //         dose_base: "",

          //         base_unit: this.chufangdata.service[0].once + "次",

          //         price: "",

          //         usage: this.chufangdata.service[0].service.remark,
          //         each_dos: "",
          //         fee_category: "",
          //       },
          //     });
          //   });
          //   this.chufangdata.drug.forEach((item) => {
          //     item.drug.each_dos = item.each_dos
          //       ? this.thatF.pinci.find((res) => res.id == item.each_dos)[
          //           "name"
          //         ]
          //       : "";
          //     item.drug.usage = item.usage
          //       ? this.thatF.geiyao.find((res) => res.id == item.usage)["name"]
          //       : "";
          //   });
          // } else {
          //   this.chufangdata.drug.forEach((item) => {
          //     item.drug.each_dos = item.each_dos
          //       ? this.thatF.pinci.find((res) => res.id == item.each_dos)[
          //           "name"
          //         ]
          //       : "";
          //     item.drug.usage = item.usage
          //       ? this.thatF.geiyao.find((res) => res.id == item.usage)["name"]
          //       : "";
          //   });
          // }
          // console.log(this.chufangdata, "0000011111");

          // var cfdata = JSON.stringify(this.chufangdata);
          // if (this.order_type == 3) {
          //   const { href } = this.$router.resolve({
          //     path: "/bai/chufangje",
          //     query: { cfdata: cfdata },
          //   });
          //   window.open(href, "_blank");
          // } else {
          //   const { href } = this.$router.resolve({
          //     path: "/bai/chufang",
          //     query: { cfdata: cfdata },
          //   });
          //   window.open(href, "_blank");
          // }
        }, 1000);
      }

      // this.thatF.getDrugItem();
    },
  },
  components: {
    ViewTitle,
    bllist,
    chufang,
    chufangje,
    selectPrint,
  },
};
</script>
<style lang='scss' scoped>
.userinfo {
  display: flex;
  align-items: center;
  border: 1px solid #e7e7e7;
  padding-left: 30px;
  line-height: 60px;
  border-radius: 20px;
  margin-bottom: 20px;

  >div {
    flex: 1;
  }
}

.buts {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.selects {
  position: relative;
  // /deep/ .el-input{
  //   width: 300px;
  // }

  .selectTables {
    width: 300px;
  }
}

.bl {
  /deep/ .el-dialog {
    width: 70%;
    height: 80vh;
    overflow: scroll;
  }
}
</style>
